package com.fjycnet.eventbus;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.orangelife.R;

import org.greenrobot.eventbus.EventBus;

public class EbSecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eb_second);
        setListener();
    }

    //使用EventBus发消息给订阅此消息的Activity(观察者)
    private void postEvent() {
        MyMessageEvent event = new MyMessageEvent("我是从上个界面传来的消息啊", "1000");
        EventBus.getDefault().post(event);
    }

    private void jumpBack() {
        finish();
    }

    private void setListener() {
        findViewById(R.id.btnClose).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                jumpBack();
            }
        });
        findViewById(R.id.btnSend).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                postEvent();
            }
        });
    }
}
